#include "people.h"
#include<QPixmap>
#include<QKeyEvent>
#include"Gamesetting.h"
using namespace gamesetting;
people::people(QGraphicsPixmapItem *parent):QGraphicsPixmapItem(parent)
{
    setPixmap(QPixmap(":/zhongli.png"));
    setScale(peoplescale);
    setPos(boundingRect().height()*peoplescale/2,windowheight/2-boundingRect().width()*peoplescale/2);
    setFlag(QGraphicsItem::ItemIsFocusable);
    setFocus();
}

void people::keyPressEvent(QKeyEvent *event)
{
    switch(event->key())
    {
    case Qt::Key_W:
        if(pos().y()>0)
            setPos(x(),y()-gamesetting::movelength);
        break;
    case Qt::Key_S:
        if(pos().y()<windowwidth-boundingRect().height()*peoplescale/2)
            setPos(x(),y()+gamesetting::movelength);
        break;
    }

}
